<?php

/**
 * This is the model class for table "occupancy".
 *
 * The followings are the available columns in table 'occupancy':
 * @AddressOne integer $id
 * @AddressOne integer $idTenant
 * @AddressOne integer $idRentalproperty
 * @AddressOne integer $idRentalUnit
 * @AddressOne string $MoveInDate
 * @AddressOne string $SoftwareTenantNumber
 * @AddressOne string $MoveOutDate
 * @AddressOne string $LeaseEndDate
 * @AddressOne string $Occupancycol
 * @AddressOne string $MonthToMonthTenancy
 *
 * The followings are the available model relations:
 * @AddressOne Leaseviolations[] $leaseviolations
 * @AddressOne Moveout[] $moveouts
 * @AddressOne Rentalunit $idRentalUnit0
 * @AddressOne Tenant $idTenant0
 * @AddressOne RentalAddressOne $idRentalproperty0
 * @AddressOne Tenantpaymenthistory[] $tenantpaymenthistories
 * @AddressOne Tenantrebuttal[] $tenantrebuttals
 */
class Occupancy extends CActiveRecord
{
	public $AddressOne,$UnitNumber,$userName,$tfirstName,$tlastName;
	
	/**
	 * Returns the static model of the specified AR class.
	 * @return Occupancy the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'occupancy';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('idTenant, idRentalProperty, idRentalUnit', 'numerical', 'integerOnly'=>true),
			array('SoftwareTenantNumber', 'length', 'max'=>15),
			array('MonthToMonthTenancy', 'length', 'max'=>1),
			array('MoveInDate, MoveOutDate, LeaseEndDate, Occupancycol', 'safe'),
			array('idTenant, idRentalProperty, idRentalUnit, MoveInDate','required'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('tfirstName,tlastName,AddressOne, UnitNumber, userName, id, idTenant, idRentalProperty, idRentalUnit, MoveInDate, SoftwareTenantNumber, MoveOutDate, LeaseEndDate, Occupancycol, MonthToMonthTenancy', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'leaseviolations' => array(self::HAS_ONE, 'Leaseviolations', 'idOccupancy'),
			'moveouts' => array(self::HAS_ONE, 'Moveout', 'idOccupancy'),
			'idRentalUnit0' => array(self::BELONGS_TO, 'Rentalunit', 'idRentalUnit'),
			'idTenant0' => array(self::BELONGS_TO, 'Tenant', 'idTenant'),
			'idRentalProperty0' => array(self::BELONGS_TO, 'Rentalproperty', 'idRentalProperty'),
			'tenantpaymenthistories' => array(self::HAS_MANY, 'Tenantpaymenthistory', 'idOccupancy'),
			'tenantrebuttals' => array(self::HAS_MANY, 'Tenantrebuttal', 'idOccupancy'),
			'payments' => array(self::HAS_MANY, 'Payments', 'idOccupancy'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'idTenant' => 'Id Tenant',
			'idRentalProperty' => 'Id Rental AddressOne',
			'idRentalUnit' => 'Id Rental Unit',
			'MoveInDate' => 'Move In Date',
			'SoftwareTenantNumber' => 'Software Tenant Number',
			'MoveOutDate' => 'Move Out Date',
			'LeaseEndDate' => 'Lease End Date',
			'Occupancycol' => 'Occupancycol',
			'MonthToMonthTenancy' => 'Month To Month Tenancy',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.
		 $sort = new CSort();
		 $sort->attributes = array(

		   'userName'=>array(
		      'asc'=>$this->userName,
		      'desc'=>$this->userName,
				 ),
		
			'MoveInDate' => array(
               'asc'=>'MoveInDate',
               'desc'=>'MoveInDate desc',
             ),
				 
		   'AddressOne'=>array(
		      'asc'=>$this->AddressOne,
		      'desc'=>$this->AddressOne,
				 ),
				 
			'SoftwareTenantNumber' => array(
               'asc'=>'SoftwareTenantNumber',
               'desc'=>'SoftwareTenantNumber desc',
             ),		 
		
		   'UnitNumber'=>array(
		      'asc'=>$this->UnitNumber,
		      'desc'=>$this->UnitNumber,
		 		),
		 		
		 
		 );
		
		
		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('idTenant',$this->idTenant);
		$criteria->compare('idRentalProperty',$this->idRentalProperty);
		$criteria->compare('idRentalUnit',$this->idRentalUnit);
		$criteria->compare('MoveInDate',$this->MoveInDate,true);
		$criteria->compare('SoftwareTenantNumber',$this->SoftwareTenantNumber,true);
		$criteria->compare('MoveOutDate',$this->MoveOutDate,true);
		$criteria->compare('LeaseEndDate',$this->LeaseEndDate,true);
		$criteria->compare('Occupancycol',$this->Occupancycol,true);
		$criteria->compare('MonthToMonthTenancy',$this->MonthToMonthTenancy,true);
		$criteria->compare('userName', $this->userName, true);
		$criteria->compare('AddressOne', $this->AddressOne, true);
		$criteria->compare('UnitNumber', $this->UnitNumber, true);
		$criteria->compare('FirstName', $this->tfirstName, true);
		$criteria->compare('LastName', $this->tlastName, true);
		
		//$criteria->compare('LastName', $this->userName, true);
		$criteria->with=array('idRentalUnit0','idRentalProperty0','idTenant0','idTenant0.iduser0');
		$criteria->together=true;
		return new CActiveDataProvider(get_class($this), array(
			'criteria'=>$criteria,
			'sort'=>$sort,
		));
	}
	
}